#include "stdafx.h"
#include "Model.h"


Model::Model(char * file)
{
	fileName = file;
	model = NULL;
}

void Model::Display()
{
	// Load the model only if it hasn't been loaded before
	// If it's been loaded then pmodel1 should be a pointer to the model geometry data...otherwise it's null
    if (!model) 
	{
		// this is the call that actualy reads the OBJ and creates the model object
        model = glmReadOBJ(fileName);	
        if (!model) exit(0);
		// This will rescale the object to fit into the unity matrix
		// Depending on your project you might want to keep the original size and positions you had in 3DS Max or GMAX so you may have to comment this.
        glmUnitize(model);
		// These 2 functions calculate triangle and vertex normals from the geometry data.
		// To be honest I had some problem with very complex models that didn't look to good because of how vertex normals were calculated
		// So if you can export these directly from you modeling tool do it and comment these line
		// 3DS Max can calculate these for you and GLM is perfectly capable of loading them
        glmFacetNormals(model);        
		glmVertexNormals(model, 90.0);
    }
    // This is the call that will actualy draw the model
	// Don't forget to tell it if you want textures or not :))
    glmDraw(model, GLM_SMOOTH| GLM_TEXTURE);
}